package com.mingren.controller;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.mingren.annotation.AuthCheck;
import com.mingren.api.aliyunai.AiPictureToMp4;
import com.mingren.api.aliyunai.AliYunAiApi;
import com.mingren.api.aliyunai.model.CreateOutPaintingTaskResponse;
import com.mingren.api.aliyunai.model.GetOutPaintingTaskResponse;
import com.mingren.api.aliyunai.modelPictureToMp4.CreateOutMp4askResponse;
import com.mingren.api.aliyunai.modelPictureToMp4.GetOutMp4TaskResponse;
import com.mingren.api.imagesearch.ImageSearchApiFacade;
import com.mingren.api.imagesearch.model.ImageSearchResult;
import com.mingren.common.BaseResponse;
import com.mingren.common.DeleteRequest;
import com.mingren.common.ResultUtils;
import com.mingren.constant.UserConstant;
import com.mingren.exception.BusinessException;
import com.mingren.exception.ErrorCode;
import com.mingren.exception.ThrowUtils;
import com.mingren.manager.annotation.SaSpaceCheckPermission;
import com.mingren.manager.auth.SpaceUserAuthManager;
import com.mingren.manager.auth.StpKit;
import com.mingren.manager.auth.model.SpaceUserPermissionConstant;
import com.mingren.model.domain.Picture;
import com.mingren.model.domain.Space;
import com.mingren.model.domain.User;
import com.mingren.model.dto.pictureRequest.*;
import com.mingren.model.enums.PictureReviewStatusEnum;
import com.mingren.model.vo.PictureTagCategory;
import com.mingren.model.vo.PictureVO;
import com.mingren.model.vo.SpaceVO;
import com.mingren.service.PictureService;
import com.mingren.service.SpaceService;
import com.mingren.service.UserService;
import com.mingren.utils.Rediskey;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author 曹宏福
 * @version 1.0
 * 文件上传控制器
 */
@RestController
@RequestMapping("/picture")
@Slf4j
public class PictureController {

    @Resource
    private PictureService pictureService;

    @Resource
    private UserService userService;

    @Resource
    private SpaceService spaceService;

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Resource
    private AliYunAiApi aliYunAiApi;

    @Resource
    private AiPictureToMp4 aiPictureToMp4;

    @Resource
    private SpaceUserAuthManager spaceUserAuthManager;

    /**
     * todo 本地缓存 + redis多级缓存策略 finished
     * todo 实现
     * todo redisson解决缓存击穿  Redisson 实现分布式锁
     * todo redisson解决缓存穿透
     */
    @Resource
    private RedissonClient redissonClient;

    /**
     * 该对象相当于map key相当于键 value相当于数据
     */
    private final Cache<String, String> LOCAL_CACHE =
            Caffeine.newBuilder().initialCapacity(1024)
                    .maximumSize(10000L) //缓存的键值对达到10000个之后会移除一些缓存项
                    // 缓存 5 分钟移除
                    .expireAfterWrite(5L, TimeUnit.MINUTES)
                    .build(); //创建Cache实例

    /**
     * 图片分页查询(走Redis缓存):返回脱敏后的图片集合
     *
     * @param pictureQueryRequest: 图片查询请求体
     * @param request:             请求
     * @return
     */
    @PostMapping("/list/page/vo/cache")
    @ApiOperation(value = "图片分页查询【本地缓存 + redis缓存】")
    public BaseResponse<Page<PictureVO>> listPictureVOByPageWithCache(@RequestBody PictureQueryRequest pictureQueryRequest, HttpServletRequest request) {
        //获取第几页的数据
        long current = pictureQueryRequest.getCurrent();
        //获取几条数据
        long size = pictureQueryRequest.getPageSize();
        // 限制爬虫 如果获取条数大于20条,抛出异常
        ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR, "限制20张图片");
        // 普通用户默认只能看到审核通过的数据
        pictureQueryRequest.setReviewStatus(PictureReviewStatusEnum.PASS.getValue());
        // todo 构建key
        // 1、获得rediskey：rediskey就是将查询体转为Json
        String queryCondition = JSONUtil.toJsonStr(pictureQueryRequest);
        // 2、加密key
        String sercretKey = DigestUtils.md5DigestAsHex(queryCondition.getBytes());
        // 3、获得key
        String key = Rediskey.GetRedisKey(sercretKey);
        // 查询缓存 redis + 本地缓存

        // 查询本地缓存
        String localCache = LOCAL_CACHE.getIfPresent(key);
        // 如果本地缓存有数据直接返回
        if (localCache != null) {
            //将String转换
            Page<PictureVO> cachedPage = JSONUtil.toBean(localCache, Page.class);
            return ResultUtils.success(cachedPage);
        }
        // todo 如果本地缓存不存在数据 则查询redis中的数据
        // 4、从redis查询数据
        ValueOperations<String, String> valueOps = stringRedisTemplate.opsForValue();
        String cachedValue = valueOps.get(key);
        if (cachedValue != null) {
            //如果查询到的数据不为空 则直接返回数据
            Page<PictureVO> cachedPage = JSONUtil.toBean(cachedValue, Page.class);
            return ResultUtils.success(cachedPage);
        }
        Page<Picture> picturePage = null;
        //todo redisson解决缓存击穿 防止直接并发请求打到数据库
        // 获取一个分布式锁
        RLock lock = redissonClient.getLock(Rediskey.GetLockKey());
        try {
            //尝试获取到锁
            if (lock.tryLock(0, -1, TimeUnit.MILLISECONDS)) {
                //查询数据库 设置缓存
                // 5、如果redis中没查询 到 则查询数据库
                picturePage = pictureService.page(new Page<>(current, size),
                        pictureService.getQueryWrapper(pictureQueryRequest));
                // 6、将查询到的数据保存在redis->转换为Json子串
                String cacheValue = JSONUtil.toJsonStr(picturePage);
                // 7、为避免缓存雪崩将过期时间设置为随机时间(5,10)分钟
                int expireTime = RandomUtil.randomInt(5, 10);
                //将查询的数据放入redis
                valueOps.set(key, cacheValue, expireTime, TimeUnit.MINUTES);
                //将查询的数据放入本地缓存
                LOCAL_CACHE.put(key, cacheValue);
            }
        } catch (InterruptedException e) {
            log.error("doCacheRecommendUser error", e);
        } finally {
            //缓存执行之后将分布式锁关闭
            //如果线程中存在分布式锁 则释放当前客户端的分布式锁
            if (lock.isHeldByCurrentThread()) {
                System.out.println("unlock: " + Thread.currentThread().getId());
                //如果存在分布式锁 则将释放当前客户端的分布式锁
                lock.unlock();
            }
        }
        // 获取封装类
        return ResultUtils.success(pictureService.getPictureVOPage(picturePage, request));
    }

    /**
     * 图片分页查询:返回脱敏后的图片集合
     *
     * @param pictureQueryRequest: 图片查询请求体
     * @param request:             请求
     * @return
     */
    @PostMapping("/list/page/vo")
    @ApiOperation(value = "图片分页查询【走数据库测试的接口】")
    public BaseResponse<Page<PictureVO>> listPictureVOByPage(@RequestBody PictureQueryRequest pictureQueryRequest, HttpServletRequest request) {
        //获取第几页的数据
        long current = pictureQueryRequest.getCurrent();
        //获取几条数据
        long size = pictureQueryRequest.getPageSize();
        // 限制爬虫 如果获取条数大于20条,抛出异常
        ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR, "限制20张图片");
        //空间权限校验
        Long spaceId = pictureQueryRequest.getSpaceId();
        if (spaceId == null) {
            // 如果查询的为公开图库
            // 普通用户默认只能看到审核通过的数据
            // 设置审核状态为通过
            pictureQueryRequest.setReviewStatus(PictureReviewStatusEnum.PASS.getValue());
            // 设置只查询spaceID为null的数据
            pictureQueryRequest.setNullSpaceId(true);
        } else {
            // 如果分页查询的是私有图库
            // 需要权限校验
            User loginUser = userService.getLoginUser(request);
            Space space = spaceService.getById(spaceId);
            //判断该空间是否存在
            ThrowUtils.throwIf(space == null, ErrorCode.NOT_FOUND_ERROR, "空间不存在");
            //判断是否本人操作
            if (!loginUser.getId().equals(space.getUserId())) {
                throw new BusinessException(ErrorCode.NO_AUTH, "没有空间权限");
            }
        }
        // 查询数据库
        Page<Picture> picturePage = pictureService.page(new Page<>(current, size),
                pictureService.getQueryWrapper(pictureQueryRequest));
        // 获取封装类
        return ResultUtils.success(pictureService.getPictureVOPage(picturePage, request));
    }

    /**
     * 开发审核接口【管理员可用】
     *
     * @param pictureReviewRequest
     * @param request
     * @return
     */
    @ApiOperation(value = "开发审核接口【管理员可用】")
    @PostMapping("/review")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> doPictureReview(@RequestBody PictureReviewRequest pictureReviewRequest,
                                                 HttpServletRequest request) {
        ThrowUtils.throwIf(pictureReviewRequest == null, ErrorCode.PARAMS_ERROR);
        User loginUser = userService.getLoginUser(request);
        pictureService.doPictureReview(pictureReviewRequest, loginUser);
        return ResultUtils.success(true);
    }

    /**
     * 上传图片（可重新上传）
     *
     * @param multipartFile:       上传文件流
     * @param pictureUploadRequest : 图片上传/修改请求体
     * @param request              : 请求
     * @return
     */
    @ApiOperation(value = "文件上传图片【本人或管理员调用接口】")
    @PostMapping("/upload")
    @SaSpaceCheckPermission(value = SpaceUserPermissionConstant.PICTURE_UPLOAD)
    //@AuthCheck(mustRole = UserConstant.ADMIN_ROLE) 注销权限校验 改为接口仅本人或管理员可用
    public BaseResponse<PictureVO> uploadPicture(@RequestPart("file") MultipartFile multipartFile, PictureUploadRequest pictureUploadRequest, HttpServletRequest request) {
        User loginUser = userService.getLoginUser(request);
        PictureVO pictureVO = pictureService.uploadPicture(multipartFile, pictureUploadRequest, loginUser);
        return ResultUtils.success(pictureVO);
    }

    /**
     * 上传图片（可重新上传）
     *
     * @param pictureUploadRequest : 图片上传/修改请求体
     * @param request              : 请求
     * @return
     */
    @ApiOperation(value = "URL上传图片【本人或管理员调用接口】")
    @PostMapping("/upload/url")
    @SaSpaceCheckPermission(value = SpaceUserPermissionConstant.PICTURE_UPLOAD)
    //@AuthCheck(mustRole = UserConstant.ADMIN_ROLE) 注销权限校验 改为接口仅本人或管理员可用
    public BaseResponse<PictureVO> uploadPictureByUrl(@RequestBody PictureUploadRequest pictureUploadRequest, HttpServletRequest request) {
        String fireUrl = pictureUploadRequest.getFileUrl();
        User loginUser = userService.getLoginUser(request);
        PictureVO pictureVO = pictureService.uploadPicture(fireUrl, pictureUploadRequest, loginUser);
        return ResultUtils.success(pictureVO);
    }

    /**
     * 分页获取图片列表（仅管理员可用）
     */
    @PostMapping("/list/page")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    @ApiOperation(value = "分页获取图片列表（仅管理员可用）")
    public BaseResponse<Page<Picture>> listPictureByPage(@RequestBody PictureQueryRequest pictureQueryRequest) {
        long current = pictureQueryRequest.getCurrent();
        long size = pictureQueryRequest.getPageSize();
        // 查询数据库
        Page<Picture> picturePage = pictureService.page(new Page<>(current, size),
                pictureService.getQueryWrapper(pictureQueryRequest));
        return ResultUtils.success(picturePage);
    }

    /**
     * 根据 id 获取图片（仅管理员可用）
     */
    @GetMapping("/get")
    @ApiOperation(value = "根据 id 获取图片（仅管理员可用）")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<Picture> getPictureById(long id, HttpServletRequest request) {
        //判空
        ThrowUtils.throwIf(id <= 0, ErrorCode.PARAMS_ERROR);
        //查询数据库
        Picture picture = pictureService.getById(id);
        ThrowUtils.throwIf(picture == null, ErrorCode.NOT_FOUND_ERROR, "数据库查询失败");
        // 获取封装类
        return ResultUtils.success(picture);
    }

    /**
     * 根据 id 获取图片（封装类）
     */
    @GetMapping("/get/vo")
    @ApiOperation(value = "根据 id 获取图片（封装类）用户接口")
    public BaseResponse<PictureVO> getPictureVOById(long id, HttpServletRequest request) {
        ThrowUtils.throwIf(id <= 0, ErrorCode.PARAMS_ERROR);
        // 查询数据库
        Picture picture = pictureService.getById(id);
        ThrowUtils.throwIf(picture == null, ErrorCode.NOT_FOUND_ERROR);
        // 空间的图片，需要校验权限
        Space space = null;
        Long spaceId = picture.getSpaceId();
        if (spaceId != null) {
            //判断
            boolean hasPermission = StpKit.SPACE.hasPermission(SpaceUserPermissionConstant.PICTURE_VIEW);
            ThrowUtils.throwIf(!hasPermission, ErrorCode.NO_AUTH);
            space = spaceService.getById(spaceId);
            ThrowUtils.throwIf(space == null, ErrorCode.NOT_FOUND_ERROR, "空间不存在");
        }
        // 获取权限列表
        User loginUser = userService.getLoginUser(request);
        List<String> permissionList = spaceUserAuthManager.getPermissionList(space, loginUser);
        PictureVO pictureVO = pictureService.getPictureVO(picture, request);
        pictureVO.setPermissionList(permissionList);
        // 获取封装类
        return ResultUtils.success(pictureVO);
    }

    /**
     * 删除图片
     * 普通用户的私有空间删除图片
     * @param deleteRequest
     * @param request
     * @return
     */
    @PostMapping("/delete")
    //@AuthCheck(mustRole = UserConstant.ADMIN_ROLE) 解除仅仅用户管理员才能删除图片
    @SaSpaceCheckPermission(value = SpaceUserPermissionConstant.PICTURE_DELETE) // St-token 逻辑
    //@ApiOperation(value = "删除图片,仅管理员可用")  删除图片接口 要求能删除公共图库和私有图库的照片 并且权限为私有图库本人和管理员
    public BaseResponse<Boolean> deletePicture(@RequestBody DeleteRequest deleteRequest
            , HttpServletRequest request) {
        if (deleteRequest == null || deleteRequest.getId() <= 0) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        User loginUser = userService.getLoginUser(request);
        Long id = deleteRequest.getId();
        //删除图片
        pictureService.deletePicture(id, loginUser);
        return ResultUtils.success(true);
    }

    /**
     * 更新图片（仅管理员可用）
     */
    @PostMapping("/update")
    @ApiOperation(value = "更新图片（仅管理员可用）")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> updatePicture(@RequestBody PictureUpdateRequest pictureUpdateRequest, HttpServletRequest request) {
        if (pictureUpdateRequest == null || pictureUpdateRequest.getId() <= 0) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        // 将实体类和 DTO 进行转换
        Picture picture = new Picture();
        BeanUtils.copyProperties(pictureUpdateRequest, picture);
        // 注意将 list 转为 string
        picture.setTags(JSONUtil.toJsonStr(pictureUpdateRequest.getTags()));
        // 数据校验
        pictureService.validPicture(picture);
        // 判断是否存在
        long id = pictureUpdateRequest.getId();
        //获取数据库图片信息
        Picture oldPicture = pictureService.getById(id);
        ThrowUtils.throwIf(oldPicture == null, ErrorCode.NOT_FOUND_ERROR);
        //补充审核参数
        User loginUser = userService.getLoginUser(request);
        //填充参数
        pictureService.fillReviewParams(oldPicture, loginUser);
        // 操作数据库
        boolean result = pictureService.updateById(picture);
        ThrowUtils.throwIf(!result, ErrorCode.NOT_FOUND_ERROR, "数据库查询失败");
        return ResultUtils.success(true);
    }


    /**
     * 编辑图片【给用户使用】
     *
     * @return
     */
    @PostMapping("/edit")
    @ApiOperation(value = "编辑图片【用户接口】")
    @SaSpaceCheckPermission(value = SpaceUserPermissionConstant.PICTURE_EDIT)
    public BaseResponse<Boolean> editPicture(@RequestBody PictureEditRequest pictureEditRequest, HttpServletRequest request) {
        //1、判空
        if (pictureEditRequest == null || pictureEditRequest.getId() <= 0) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
        }
        //编辑
        pictureService.editPicture(pictureEditRequest, userService.getLoginUser(request));
        return ResultUtils.success(true);
    }

    /**
     * 批量抓取图片
     *
     * @param pictureUploadByBatchRequest:批量抓取图片请求体
     * @param request:请求
     * @return
     */
    @PostMapping("/upload/batch")
    @ApiOperation(value = "批量抓取图片【管理员接口】")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<Integer> uploadPictureByBatch(
            @RequestBody PictureUploadByBatchRequest pictureUploadByBatchRequest,
            HttpServletRequest request) {
        ThrowUtils.throwIf(pictureUploadByBatchRequest == null, ErrorCode.PARAMS_ERROR);
        User loginUser = userService.getLoginUser(request);
        // todo 改为必应搜索
        int uploadCount = pictureService.uploadPictureByBatch(pictureUploadByBatchRequest, loginUser);
        return ResultUtils.success(uploadCount);
    }

    /**
     * 获取图片标签和分类
     *
     * @return
     */
    @ApiOperation(value = "获取预置标签和分类")
    @GetMapping("/tag_category")
    public BaseResponse<PictureTagCategory> listPictureTagCategory() {
        PictureTagCategory pictureTagCategory = new PictureTagCategory();
        //标签
        List<String> tagList = Arrays.asList("热门", "搞笑", "生活", "高清", "艺术", "校园", "背景", "简历", "创意", "美女");
        //分类
        List<String> categoryList = Arrays.asList("模板", "电商", "表情包", "素材", "海报", "老师");
        pictureTagCategory.setTagList(tagList);
        pictureTagCategory.setCategoryList(categoryList);
        return ResultUtils.success(pictureTagCategory);
    }

    /**
     * 以图搜图接口
     */
    @PostMapping("/search/picture")
    public BaseResponse<List<ImageSearchResult>> searchPictureByPicture(@RequestBody SearchPictureByPictureRequest searchPictureByPictureRequest) {
        //判空
        ThrowUtils.throwIf(searchPictureByPictureRequest == null, ErrorCode.PARAMS_ERROR);
        //获取需要识图的图片id
        Long pictureId = searchPictureByPictureRequest.getPictureId();
        //判空
        ThrowUtils.throwIf(pictureId == null || pictureId <= 0, ErrorCode.PARAMS_ERROR);
        //获取数据库老图片
        Picture oldPicture = pictureService.getById(pictureId);
        //再次判空
        ThrowUtils.throwIf(oldPicture == null, ErrorCode.NOT_FOUND_ERROR);
        //搜索图片接口调用 传入的是图片的url todo 需改为用的新增的jpgorpng的url success 测试通过
        //List<ImageSearchResult> resultList = ImageSearchApiFacade.searchImage(oldPicture.getUrl());
        List<ImageSearchResult> resultList = ImageSearchApiFacade.searchImage(oldPicture.getJpgOrPngUrl());
        return ResultUtils.success(resultList);
    }

    /**
     * 颜色搜图接口
     *
     * @param searchPictureByColorRequest:请求体
     * @param request:获取登录用户态
     * @return
     */
    @PostMapping("/search/color")
    @SaSpaceCheckPermission(value = SpaceUserPermissionConstant.PICTURE_VIEW)
    public BaseResponse<List<PictureVO>> searchPictureByColor(@RequestBody SearchPictureByColorRequest searchPictureByColorRequest, HttpServletRequest request) {
        ThrowUtils.throwIf(searchPictureByColorRequest == null, ErrorCode.PARAMS_ERROR);
        String picColor = searchPictureByColorRequest.getPicColor();
        Long spaceId = searchPictureByColorRequest.getSpaceId();
        User loginUser = userService.getLoginUser(request);
        List<PictureVO> result = pictureService.searchPictureByColor(spaceId, picColor, loginUser);
        return ResultUtils.success(result);
    }

    /**
     * 批量修改接口
     *
     * @param pictureEditByBatchRequest
     * @param request
     * @return
     */
    @PostMapping("/edit/batch")
    @SaSpaceCheckPermission(value = SpaceUserPermissionConstant.PICTURE_EDIT)
    public BaseResponse<Boolean> editPictureByBatch(@RequestBody PictureEditByBatchRequest pictureEditByBatchRequest, HttpServletRequest request) {
        //判空
        ThrowUtils.throwIf(pictureEditByBatchRequest == null, ErrorCode.PARAMS_ERROR, "参数为空");
        User loginUser = userService.getLoginUser(request);
        pictureService.editPictureByBatch(pictureEditByBatchRequest, loginUser);
        return ResultUtils.success(true);
    }

    /**
     * 创建 AI 扩图任务
     */
    @PostMapping("/out_painting/create_task")
    @SaSpaceCheckPermission(value = SpaceUserPermissionConstant.PICTURE_EDIT)
    public BaseResponse<CreateOutPaintingTaskResponse> createPictureOutPaintingTask(@RequestBody CreatePictureOutPaintingTaskRequest createPictureOutPaintingTaskRequest,
                                                                                    HttpServletRequest request) {
        if (createPictureOutPaintingTaskRequest == null || createPictureOutPaintingTaskRequest.getPictureId() == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        User loginUser = userService.getLoginUser(request);
        CreateOutPaintingTaskResponse response = pictureService.createPictureOutPaintingTask(createPictureOutPaintingTaskRequest, loginUser);
        return ResultUtils.success(response);
    }
    /**
     * 创建 AI 扩视频任务
     */
    @PostMapping("/out_Mp4/create_task")
    @SaSpaceCheckPermission(value = SpaceUserPermissionConstant.PICTURE_EDIT)
    public BaseResponse<CreateOutMp4askResponse> createPictureOutMp4Task(@RequestBody CreatePictureOutMp4TaskRequest createPictureOutMp4TaskRequest,
                                                                              HttpServletRequest request) {
        if (createPictureOutMp4TaskRequest == null || createPictureOutMp4TaskRequest.getPictureId() == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        User loginUser = userService.getLoginUser(request);
        CreateOutMp4askResponse response = pictureService.createPictureOutMp4Task(createPictureOutMp4TaskRequest, loginUser);
        return ResultUtils.success(response);
    }
    /**
     * 查询 AI 扩图任务
     */
    @GetMapping("/out_painting/get_task")
    public BaseResponse<GetOutPaintingTaskResponse> getPictureOutPaintingTask(String taskId) {
        ThrowUtils.throwIf(StrUtil.isBlank(taskId), ErrorCode.PARAMS_ERROR);
        GetOutPaintingTaskResponse task = aliYunAiApi.getOutPaintingTask(taskId);
        return ResultUtils.success(task);
    }
    /**
     * 查询 AI 扩视频任务
     */
    @GetMapping("/out_Mp4/get_task")
    public BaseResponse<GetOutMp4TaskResponse> getPictureOutMp4Task(String taskId) {
        ThrowUtils.throwIf(StrUtil.isBlank(taskId), ErrorCode.PARAMS_ERROR);
        GetOutMp4TaskResponse task = aiPictureToMp4.getOutMp4Task(taskId);
        return ResultUtils.success(task);
    }
}
